axios.defaults.baseURL = 'https://hmajax.itheima.net'


function showToast(msg) {
    const toastDom = document.querySelector('.my-toast')

    const toast = new bootstrap.Toast(toastDom)
    document.querySelector('.toast-body').innerText = msg
    toast.show()
}

function checkLogin() {
    const token = localStorage.getItem('token')
    if(token === null){
        showToast('请先登录')
        setTimeout(()=>{
            location.href = 'login.html'
        },1500)
    }
}

function renderUsername() {
    const username = localStorage.getItem('username')
    document.querySelector('.username').innerText = username

}

function registerLogout() {
    document.querySelector('#logout').addEventListener('click',()=> {
        localStorage.removeItem('token')
        localStorage.removeItem('username')
        location.href = 'login.html'
    })
}